629B - Far Relative’s Problem - CodeForces Solution


brute force *1100

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
 
const int DAYS = 371;
int party[2][DAYS];
// 0 -> female
// 1 -> male
 
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	vector<pair<int,int>> male;
	vector<pair<int,int>> female;
	
	for(int i = 0; i < n; i++){
		char s;
		int a, b;
		cin >> s >> a >> b;
		if(s == 'F') female.push_back({a, b});
		else male.push_back({a, b});
	}
	
	int m = male.size();
	int f = female.size();
	
	if(m == 0 or f == 0){
		cout << 0 << '\n';
		return 0;
	}
	
	for(int i = 1; i <= 366; i++){
		for(int j = 0; j < m; j++){
			if(male[j].first <= i and i <= male[j].second){
				party[1][i]++;
			}
		}
		
		for(int k = 0; k < f; k++){
			if(female[k].first <= i and i <= female[k].second){
				party[0][i]++;
			}
		}
	}
	
	int ans = 0;
	
	for(int i = 1; i <= 366; i++){
		ans = max(ans, min(party[0][i], party[1][i])); 
	}
	
	cout << ans*2 << '\n';
	return 0;
}


Comments

Submit
0 Comments
More Questions

977C - Less or Equal
1505C - Fibonacci Words
1660A - Vasya and Coins
1660E - Matrix and Shifts
1293B - JOE is on TV
1584A - Mathematical Addition
1660B - Vlad and Candies
1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity
1627B - Not Sitting
1663C - Pōja Verdon
1497A - Meximization
1633B - Minority
688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It
1335B - Construct the String
1004B - Sonya and Exhibition
1397A - Juggling Letters
985C - Liebig's Barrels
115A - Party
746B - Decoding
1424G - Years
1663A - Who Tested